package com.efast.cafe.portal.controller.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.portal.bean.common.PortalCommonLaudBean;
import com.efast.cafe.portal.entity.common.PortalCommonLaud;
import com.efast.cafe.portal.service.common.IPortalCommonLaudService;

/**
 * 點贊
 * @author fxm
 *
 */
@Controller
public class CommonLaudController extends AbstractController{
	@Autowired
	private IPortalCommonLaudService portalCommonLaudService;

	
	
	/**
	 * 获取业务对象的点赞数
	 * @param objectType
	 * @param objectId
	 * @return
	 */
	@RequestMapping(value = "/frame_center/common/queryLaud")
	public @ResponseBody PortalCommonLaudBean queryLaud(@RequestParam Integer objectId,@RequestParam String objectType){
		PortalCommonLaudBean count = portalCommonLaudService.queryLaud(objectId, objectType);
		return count;
	}
	
	
	/**
	 * 添加點贊
	 * @param msg
	 * @return
	 */
	@RequestMapping(value = "/frame_center/common/addLaud")
	public @ResponseBody ResultBean addLaud(@ModelAttribute("laud") PortalCommonLaud laud){
		try{
			portalCommonLaudService.addLaud(laud);
			return new ResultBean(true,ADD_SUCCESS_TIP);
		}catch(Exception e){
			return new ResultBean(false, ADD_FAILURE_TIP);
		}
		
	}
	

	/**
	 * 取消點贊
	 * @param msg
	 * @return
	 */
	@RequestMapping(value = "/frame_center/common/delLaud")
	public @ResponseBody ResultBean delLaud(@RequestParam String objectType,@RequestParam Integer objectId){
		try{
			portalCommonLaudService.delLaud(objectId, objectType);
			return new ResultBean(true,DEL_SUCCESS_TIP);
		}catch(Exception e){
			return new ResultBean(false, DEL_FAILURE_TIP);
		}
		
	}
}
